<?php

/* *
 * 资讯
 */
namespace Common\Model;
use Think\Model;
class SpecialOrderModel extends BaseModel {

    public function queryForList($page=null, $map=null) {
        $list = $this->alias("so")
            ->join("left join __ADMIN__ e on e.employee_id = so.employee_id")
            ->join("left join __ADMIN__ ad on ad.employee_id = so.delivery_id")
            ->join("left join __ADMIN__ pv on pv.employee_id = so.approve_id")
            ->join("left join __SPECIAL_PRODUCT__ sp on sp.special_product_id = so.special_product_id")
            ->join("left join __CLASS__ cl on cl.class_id = sp.class_id")
            ->where(getWhereSqlByMap($map))
            ->order("so.create_time desc")
            ->limit($page->firstRow . ',' . $page->listRows)
            ->field("so.*, sp.name, e.admin_name, ad.admin_name as delivery_name, pv.admin_name as approve_name, cl.class_name")
            ->select();

        return $list;

    }

    public function getListCount($map = null) {

        $count = $this->alias("so")
            ->join("left join __SPECIAL_PRODUCT__ sp on sp.special_product_id = so.special_product_id")
//            ->join("left join __CUSTOMER__ cus on cus.customer_id = o.customer_id")
            ->where(getWhereSqlByMap($map))
            ->count();

        return $count;
    }

}

